/*
 * uc_led.c
 * Project 03
 * Nicole Ang (nang1@asu.edu)
 * Bijan Fakhri (bfakhri@asu.edu)
 * CSE325 Embedded Microprocessor Systems
 * Spring 2013
 */

#include "uc_led.h"

/* Calls uc_led_off() four times to turn all LED's off. */
void uc_led_all_off(){
	uc_led_off(1);
	uc_led_off(2);
	uc_led_off(3);
	uc_led_off(4);
}

/* Calls uc_led_on() four times to turn all LED's on. */
void uc_led_all_on(){
	uc_led_on(1);
	uc_led_on(2);
	uc_led_on(3);
	uc_led_on(4);
}

/* Calls uc_led_toggle() four times to toggle all LED's. */
void uc_led_all_toggle(){
	uc_led_toggle(1);
	uc_led_toggle(2);
	uc_led_toggle(3);
	uc_led_toggle(4);
}

/* Calls gpio_port_tc_init() to initialize the 
 * pin that each LED is connected to. */
void uc_led_init(){
	gpio_port_tc_init();
}

/* Calls gpio_port_tc_set_pin_state() to set the state of 
 * the pin for LED p_led to turn the LED off. */
void uc_led_off(int p_led){
	MCF_GPIO_CLRTC &= ~(1 << (p_led - 1));
}

/* Calls gpio_port_tc_set_pin_state() to set the state of 
 * the pin for LED p_led to turn the LED on. */
void uc_led_on(int p_led){
	MCF_GPIO_SETTC |= (1 << (p_led - 1));
}

/* Calls gpio_port_tc_get_pin_state() to determine if 
 * LED p_led is on or off. If it is on, turn it off 
 * or if it is off, turn it on. */
void uc_led_toggle(int p_led){
	int state = gpio_port_tc_get_pin_state(p_led);
	if(state)
		uc_led_off(p_led); //led is on, so turn it off
	else
		uc_led_on(p_led); //led is off, so turn it on
}